package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysExpertiseAreas;
import com.hl.sfzy.entity.SysUser;
import com.hl.sfzy.service.SysExpertiseAreasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class SysExpertiseAreasController {
    @Autowired
    private SysExpertiseAreasService sysExpertiseAreasService;
    /*
     * 新增
     * */
    @PostMapping("/SysExpertiseAreas")
    public Result add(@RequestBody SysExpertiseAreas sysExpertiseAreas){
        int num = sysExpertiseAreasService.add(sysExpertiseAreas);
        return num > 0 ? Result.success() : Result.error();
    }

    /*
     * 删除
     * */
    @DeleteMapping("/SysExpertiseAreas/{id}")
    public Result remove(@PathVariable("id") Integer id){
        int num = sysExpertiseAreasService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/SysExpertiseAreas")
    public Result removeBatch(Integer[] ids){
        int num = sysExpertiseAreasService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();

    }

    @PutMapping("/SysExpertiseAreas")
    public Result edit(@RequestBody SysExpertiseAreas sysExpertiseAreas){
        int num = sysExpertiseAreasService.edit(sysExpertiseAreas);
        return num > 0 ? Result.success() : Result.error();
    }

    @GetMapping("/SysExpertiseAreas/{id}")
    public Result findById(@PathVariable("id") Integer id){
        SysExpertiseAreas sysExpertiseAreas= sysExpertiseAreasService.findById(id);
        return Result.success(sysExpertiseAreas);
    }

    @GetMapping("/SysExpertiseAreas")
    public Result findAll(SysExpertiseAreas sysExpertiseAreas){
        List<SysExpertiseAreas> list = sysExpertiseAreasService.find(sysExpertiseAreas);
        return Result.success(list);
    }

    @GetMapping("/SysExpertiseAreas/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysExpertiseAreas sysExpertiseAreas) {
        Map<String, Object> map = sysExpertiseAreasService.findPage(pageNum, pageSize, sysExpertiseAreas);
        return Result.success(map);
    }
}
